const carService = require('../services/carService')

const carController = {
  async getCarListByShop(req, res, next) {
    try {
      let data = await carService.getCarListByShop(req.params.shop_id)
      res.send({
        code: 200,
        msg: 'ok',
        data,
      })
    } catch (error) {
      res.send({
        code: 400,
        msg: error.message,
      })
    }
  },
  async addCar(req, res, next) {
    try {
      let data = await carService.addCar(req.body)
      res.send({
        code: 200,
        msg: 'ok',
        data,
      })
    } catch (error) {
      res.send({
        code: 400,
        msg: error.message,
      })
    }
  },
  async updateCar(req, res, next) {
    try {
      let body = req.body
      let id = body._id
      delete body._id
      let data = await carService.updateCar(id, body)
      res.send({
        code: 200,
        msg: 'ok',
        data,
      })
    } catch (error) {
      res.send({
        code: 400,
        msg: error.message,
      })
    }
  },
  async deleteCar(req, res, next) {
    try {
      let data = await carService.deleteCar(req.body.id)
      res.send({
        code: 200,
        msg: 'ok',
        data,
      })
    } catch (error) {
      res.send({
        code: 400,
        msg: error.message,
      })
    }
  },
}

module.exports = carController
